import jwt
from flask import Flask
from flask_jwt_extended import JWTManager, create_access_token, decode_token

# 创建一个简单的Flask应用用于测试
app = Flask(__name__)
app.config['JWT_SECRET_KEY'] = 'erp-system-secret-key-change-in-production'
app.config['JWT_ACCESS_TOKEN_EXPIRES'] = 3600
jwt_manager = JWTManager(app)

# 测试用户ID
user_id = 2

with app.app_context():
    # 生成令牌
    token = create_access_token(identity=user_id)
    print(f"生成的令牌: {token}")
    
    try:
        # 尝试解码令牌（不验证签名）
        decoded = jwt.decode(token, 'erp-system-secret-key-change-in-production', algorithms=['HS256'], options={"verify_signature": False})
        print(f"解码的令牌: {decoded}")
        print(f"用户ID (sub): {decoded.get('sub')}")
    except Exception as e:
        print(f"解码失败: {e}")